﻿using System.Collections.Generic;
using System.Linq;
using FoosballEye.Model;

namespace FoosballEye.Repository
{
    using FoosballEye.Model.Helper;

    public class GameRepository : RepositoryBase<FoosballEyeDbContext>, IGameRepository
    {
        public OperationStatus Insert(Game game)
        {
            DataContext.Games.Add(game);
            DataContext.SaveChanges();

            return new OperationStatus { Status = true };
        }

        public Game GetLastGame()
        {
            return DataContext.Games
                .Include("BlackTeam.Attacker")
                .Include("WhiteTeam.Attacker")
                .Include("BlackTeam.Defender")
                .Include("WhiteTeam.Defender")
                .OrderByDescending(g => g.InsertDate).FirstOrDefault();
        }
    }
}
